package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.AnalysisByDay;
import com.tanhua.dubbo.api.db.AnalysisByDayApi;
import com.tanhua.dubbo.mapper.AnalysisByDayMapper;
import org.apache.dubbo.config.annotation.Service;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

@Service
public class AnalysisByDayApiImpl implements AnalysisByDayApi {

    @Autowired
    private AnalysisByDayMapper analysisByDayMapper;

    @Override
    public AnalysisByDay queryByToday(String todayStr) {
        QueryWrapper<AnalysisByDay> queryWrapper = new QueryWrapper<>();
        Date today = new DateTime(todayStr).toDate();
        queryWrapper.lambda().eq(AnalysisByDay::getRecordDate,today);
        return analysisByDayMapper.selectOne(queryWrapper);
    }

    @Override
    public void save(AnalysisByDay analysisByDay) {
        analysisByDayMapper.insert(analysisByDay);
    }

    @Override
    public void updateById(AnalysisByDay analysisByDay) {
        analysisByDayMapper.updateById(analysisByDay);
    }

    @Override
    public Long queryCumulativeUsers() {
        return analysisByDayMapper.queryCumulativeUsers();
    }

    @Override
    public Long queryActivePassDays(String pass) {
        return analysisByDayMapper.queryActivePassDays(pass);
    }

    @Override
    public Long queryNumByColumnAndDate(String columName, String dateStr) {
        return analysisByDayMapper.queryNumByColumnAndDate(columName,dateStr);
    }
}
